package com.suitsoft.ut.dao.base;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springside.modules.orm.hibernate.HibernateDao;

import com.suitsoft.ut.commons.UserHolder;
import com.suitsoft.ut.entity.account.User;
import com.suitsoft.ut.entity.base.College;

/**
 *
 *@author Suineg
 */
@Repository
public class CollegeDao extends HibernateDao<College,Long>{
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 判断学院是否存在 不存在就新建一个
	 * @param college
	 * @return
	 */
	public College isHaveCollgeNoNew(String college){
		College  collgeEntiry = findUniqueBy("collegeName", college.trim());
		if(collgeEntiry == null){
			collgeEntiry = new College();
			collgeEntiry.setCollegeName(college);
			save(collgeEntiry);
			flush();
		}
		return collgeEntiry;
	}
	
	
	public void save(College college){
		User user = new User();
		user.setId(UserHolder.getLoginUser().getId());
		college.setUser(user);
		college.setOpdate(new Date());
		super.save(college);
	}
}

